<template>
    <page-header-wrapper>
        <a-card :bordered="false">
            <div class="table-page-search-wrapper">
                <r-filter :positions="positions" :loading="loading" @query="query"/>
                <s-table :loading="loading" :cols="cols" :data="data" :actions="acts"
                         :pagination="pagination" @change="change"/>
            </div>
        </a-card>
    </page-header-wrapper>
</template>

<script>
    import STable from '@/components/Table/PagerTable'
    import RFilter from '@/components/Filter/ResumeFilter'
    import API from "@/api"
    import Adapter from "@/utils/adapter"

    export default {
        components: {
            STable,
            RFilter
        },
        data() {
            return {
                positionMap: {},
                positions: [],

                loading: true,
                data: [],
                cols: [{title: '岗位', key: 'position'}, {title: '姓名', key: 'name'},
                    {title: '学历', key: 'education'}, {title: '籍贯', key: 'nativePlace'},
                    {title: '面试状态', key: 'interviewStatusText'}, {title: '面试时间', key: 'interviewTime'},
                    {title: '签约状态', key: 'signStatusText'}, {title: '签约时间', key: 'signTime'}],
                acts: [{func: this.view, title: '查看'}],
                pagination: {
                    total: 0,
                    current: 1,
                    pageSize: 10,
                    showSizeChanger: true,
                    showQuickJumper: true
                },
                queryParams: {
                    evaluated: 2,
                    limit: 10,
                    offset: 0
                }
            }
        },
        mounted() {
            API.Position.ListAuth().then((res) => {
                if (res) {
                    this.positions = res.data || []
                    this.positionMap = {}
                    this.positions.forEach((item) => this.positionMap[item.id] = item.name)
                    this.query()
                }
            })

        },
        methods: {
            change() {
                this.queryParams.limit = this.pagination.pageSize
                this.queryParams.offset = (this.pagination.current - 1) * this.pagination.pageSize
                this.query()
            },
            query(params) {
                this.loading = true
                if (params) {
                    params.limit = this.queryParams.limit
                    params.offset = this.queryParams.offset
                    this.queryParams = params
                }
                API.Resume.List(this.queryParams).then((res) => {
                    if (res) {
                        this.pagination.total = res.total
                        Adapter.Resume(res.data, this.positionMap)
                        this.data = res.data
                    }
                }).finally(() => this.loading = false)
            },
            view(record) {
                this.$router.push({name: 'todoResumeDetails', params: {id: record.id, positionMap: this.positionMap, back: '/todo/resume'}})
            }
        }
    }
</script>
